<?php
namespace app\common\model;
use think\Model;

/**
 * user 用户会员表
 * 赵振远 2017.12.21
 * @package app\common\model
 */

class User extends Model{
	//强制类型转换
	 protected $type = [
        'create_time'  =>  'timestamp:Y/m/d H:i:s',
        'login_time' =>  'timestamp:Y/m/d H:i:s',
    ];
    // 设置pk 默认主键id
	protected $pk = 'id';
	//查询
	public function see($value=""){
		$user = User::select();
		return $user;
	}
	//更改字段值
	public function getGenderAttr($value=0){
        $gender = [0=>'保密',1=>'男',2=>'女'];
        return $gender[$value];
    }
    public function getStaticAttr($value=0){
        $static = [0=>'',1=>'正常',2=>'冻结'];
        return $static[$value];
    }
    //删除数据 暂时没用
    public function del($i){
    	$user = User::destroy($i);
    	return $user;
    }
    //条件搜索 查询nick_name 以及mobile字段
    public function scope($n,$m){
        return User::where('nick_name', 'like', $n)->whereOR('mobile', $m)->select();
    }

    /*
     * @name 指定用户id获取代理商名称
     * @author Jin
     * @date 2017.12.26
     * @param $id int 代理商id
     * @return string 用户名称
     **/
    public function getNameByUserId($id = '')
    {
        return User::where('id', $id)->value('nick_name');
    }

    //
    public function CashWith(){
        return $this->hasOne('CashWith','c_id');
    }

    /**
     * 关联用户账户表，查找用户账户金额
     * @return $this
     */
    public function userAccount(){
        return $this->hasOne('UserAccount','ua_user','id')->bind('ua_brokerage,ua_coupons,ua_account,ua_user,ua_id');
    }

}